<?php
require_once('table.php');

class Artists extends Table{
	function Artists(){
		parent::Table();
		$this->load->model('cmf_artist_model');
		$this->model = $this->cmf_artist_model;
	}
	
	/* for different functions need to have different views */
	function save($id = null, $ajax = 0){
		if( !$this->input->post('cancel') && $id ){
			if( count($_POST) && isset($_POST['password'])){
				$password = trim($_POST['password']);
				if( empty($password) ){
					unset($_POST['password']);
					unset($_POST['password_confirm']);
					unset($this->model->fields['password']);
					unset($this->model->fields['password_confirmation']);
				}
			}
		}
		parent::save($id, $ajax);
	}
	
	function edit( $id = null, $view = CMF_DEFAULT_TABLE_EDIT_VIEW, $data = array() ){
		if( !isset($data['item']) ){
			if( !empty($id) ){
				$data['item'] = $this->model->getItem( $id);
			}else{
				$data['item'] = $this->model->getEmptyItem();
			}
			$this->getTableAndFieldData($data, $id);
		}
		$data['item']->password = $data['item']->password_confirmation = null;
		$this->load->library('form_validation');
		$this->load->helper('form');
		$this->load->view($view, $data);
	}
}
?>